package com.wx.controller;

import com.alibaba.fastjson.JSONObject;
import com.wx.model.NavigationModel;
import com.wx.service.INavigationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/back/navigation")
public class navigationController {
    @Autowired
    INavigationService iNavigationService;

    @GetMapping("/findAll")
    public JSONObject findAll(){
        List<NavigationModel> list=iNavigationService.findAll();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("list",list);
        return jsonObject;
    }

    @PostMapping("/navigationAdd")
    public JSONObject navigationAdd(@RequestBody NavigationModel navigationModel){
        int result=iNavigationService.navigationAdd(navigationModel);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("result",result);
        return jsonObject;
    }

    @RequestMapping("/findById")
    public JSONObject findById(@RequestBody NavigationModel navigationModel){
        NavigationModel navigation=iNavigationService.findById(navigationModel);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("navigationModel",navigation);
        return jsonObject;
    }

    @RequestMapping("/update")
    public JSONObject update(@RequestBody NavigationModel navigationModel){
        int resutl=iNavigationService.update(navigationModel);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("resutl",resutl);
        return jsonObject;
    }

    @RequestMapping("/deleteById")
    public JSONObject deleteById(@RequestBody NavigationModel navigationModel){
        int result=iNavigationService.deleteById(navigationModel);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("result",result);
        return jsonObject;
    }
}
